function SelectList(objID)
{
    this.fromListBox=document.getElementById('SelectList_'+objID+'_UnSelected');
    this.toListBox=document.getElementById('SelectList_'+objID+'_Selected');
    this.btnAdd=document.getElementById('SelectList_'+objID+'_Button_Add');
    this.btnAddAll=document.getElementById('SelectList_'+objID+'_Button_AddAll');
    this.btnDelete=document.getElementById('SelectList_'+objID+'_Button_Delete');
    this.btnDeleteAll=document.getElementById('SelectList_'+objID+'_Button_DeleteAll');
    this.hidToList=document.getElementById('hid_'+objID+'_Selected');
    this.hidFromList=document.getElementById('hid_'+objID+'_UnSelected');
    var blConfirmDelete=document.getElementById('hid_'+objID+'_blConfirmDelete').value;
    
    this.Init=function()
    {
        for(i=0;i<this.fromListBox.options.length;i++)
        {
            this.hidFromList.value += this.fromListBox.options[i].value + "~" + this.fromListBox.options[i].text +"|";
        }
        
        for(i=0;i<this.toListBox.options.length;i++)
        {
            this.hidToList.value += this.toListBox.options[i].value + "~" + this.toListBox.options[i].text +"|";
        }
    }

    this.Add = function ()
    {
       var arr = new Array();
       for(i=0;i<this.fromListBox.options.length;i++)
       {
           if (this.fromListBox.options[i].selected==true)
           {
                arr[arr.length]=this.fromListBox.options[i];
                this.AddSelection(this.toListBox,this.fromListBox.options[i]);
                this.SaveSelection(this.hidFromList,this.hidToList,this.fromListBox.options[i]);
           }
       }
       while(arr.length>0)
       {
            this.fromListBox.removeChild(arr.pop());
       }
    }
    this.AddAll = function ()
    {
       var arr = new Array();
       var strListTemp='';
       
       for(i=0;i<this.fromListBox.options.length;i++)
       {
            arr[arr.length]=this.fromListBox.options[i];
            this.AddSelection(this.toListBox,this.fromListBox.options[i]);
            this.SaveSelection(this.hidFromList,this.hidToList,this.fromListBox.options[i]);
       }
       while(arr.length>0)
       {
            this.fromListBox.removeChild(arr.pop());
       } 
    }
    this.Delete = function ()
    {
        if (blConfirmDelete == "Y" 
            && !confirm("Are you sure you want to delete this?"))
        {
            return false;
        }
        
        var arr = new Array();
        for(i=0;i<this.toListBox.options.length;i++)
        {
           if (this.toListBox.options[i].selected==true)
           {
                arr[arr.length]=this.toListBox.options[i];
                this.AddSelection(this.fromListBox,this.toListBox.options[i]);
                this.SaveSelection(this.hidToList,this.hidFromList,this.toListBox.options[i]);   
           }
        }
        while(arr.length>0)
        {
            this.toListBox.removeChild(arr.pop());
        }
    }
    this.DeleteAll = function ()
    {
        if (blConfirmDelete == "Y" 
            && !confirm("Are you sure you want to delete this?"))
        {
            return false;
        }
        
       var arr = new Array();
       for(i=0;i<this.toListBox.options.length;i++)  
       {
            arr[arr.length]=this.toListBox.options[i];
            this.AddSelection(this.fromListBox,this.toListBox.options[i]);
            this.SaveSelection(this.hidToList,this.hidFromList,this.toListBox.options[i]);   
       }
       while(arr.length>0)
       {
            this.toListBox.removeChild(arr.pop());
       } 
    }
    
    this.AddSelection=function(ToListBox,SelectedOption)
    {
        var option=document.createElement("option");    
        option.value=SelectedOption.value;
        option.innerHTML=SelectedOption.text;
        ToListBox.appendChild(option);
    }
    
    this.SaveSelection=function(hidChooseList,hidTargetList,selectedOption)
    {
        var hidValue = selectedOption.value + "~" + selectedOption.text +"|";
        hidTargetList.value += hidValue;
        hidChooseList.value = hidChooseList.value.replace(hidValue,"");
    }
    
    this.ChangeSelectSequence=function()
    {
        var hidValue='';
        for(var i=0;i<this.toListBox.options.length;i++)
        {
            hidValue+=this.toListBox.options[i].value + "~" + this.toListBox.options[i].text +"|";
        }
        this.hidToList.value=hidValue;
    }
    
    this.Up=function()
    {
        for(var i=0;i<this.toListBox.options.length;i++)
        {
           if (this.toListBox.options[i].selected==true && i>0)
           {
                var SelectOptionValue=this.toListBox.options[i].value;  
                var SelectOptionText=this.toListBox.options[i].innerHTML;
                var PreOptionValue=this.toListBox.options[i-1].value;
                var PreOptionText=this.toListBox.options[i-1].innerHTML;
                this.toListBox.options[i].value=PreOptionValue;
                this.toListBox.options[i].innerHTML=PreOptionText;
                this.toListBox.options[i-1].value=SelectOptionValue;
                this.toListBox.options[i-1].innerHTML=SelectOptionText;
                this.toListBox.options[i-1].selected=true;
                this.toListBox.options[i].selected=false;
                this.toListBox.options[i-1].focus();
                this.ChangeSelectSequence();
                break;
           }
        }
    }
    
    this.Down=function()
    {
        for(var i=0;i<this.toListBox.options.length;i++)
        {
           if (this.toListBox.options[i].selected==true && i<this.toListBox.options.length-1)
           {
                var SelectOptionValue=this.toListBox.options[i].value;  
                var SelectOptionText=this.toListBox.options[i].innerHTML;
                var NextOptionValue=this.toListBox.options[i+1].value;
                var NextOptionText=this.toListBox.options[i+1].innerHTML;
                this.toListBox.options[i].value=NextOptionValue;
                this.toListBox.options[i].innerHTML=NextOptionText;
                this.toListBox.options[i+1].value=SelectOptionValue;
                this.toListBox.options[i+1].innerHTML=SelectOptionText;
                this.toListBox.options[i+1].selected=true;
                this.toListBox.options[i].selected=false;
                this.toListBox.options[i+1].focus();
                this.ChangeSelectSequence();
                break;
           }
        }
    }
}